<template>
  <div class="category">
    <vant-search-cate-gory @click.native="searchClick"></vant-search-cate-gory>
    <div class="category-mains">
      <cate-gory-tab :categoryList="categoryList" @tabClick="tabClick"></cate-gory-tab>
      <cate-gory-list :currentData="currentData"></cate-gory-list>
    </div>
  </div>
</template>

<script>
import { getIndexAction, getCurrentAction } from "@/network/category";
import VantSearchCateGory from "./children/VantSearchCateGory";
import CateGoryTab from "./children/CateGoryTab";
import CateGoryList from "./children/CateGoryList";
export default {
  name: "index",
  components: {
    VantSearchCateGory,
    CateGoryTab,
    CateGoryList,
  },
  created() {
    this.getIndexActions();
    this.getCurrentActions()
  },
  data() {
    return {
      categoryList: [],
      currentData: {},
      id: 1005000
    };
  },
  methods: {
    // 跳到搜索页面
    searchClick() {
      this.$router.push({
        path: '/search'
      })
    },
    tabClick(id) {
      console.log(id)
      this.id = id
      this.getCurrentActions()
    },
    getIndexActions() {
      getIndexAction().then((res) => {
        console.log(res);
        this.categoryList = res.categoryList;
      });
    },
    // 分类列表数据
    getCurrentActions() {
      const datas = {
        id: this.id
      }
      // console.log(datas)
      getCurrentAction(datas).then(res => {
        console.log(res)
        this.currentData = res.data.currentOne
        console.log(this.currentData)
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.category-mains {
  display: flex;
  margin-top: 74px;
}
</style>